home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.cs.arizona.edu
/
ftp.cs.arizona.edu.tar
/
ftp.cs.arizona.edu
/
icon
/
newsgrp
/
group99a.txt
/
000207_icon-group-sender _Mon Oct 4 12:38:36 1999.msg
< prev
next >
Wrap
Internet Message Format
|
2000-09-20
|
2KB
Return-Path: <icon-group-sender>
Received: (from root@localhost)
by baskerville.CS.Arizona.EDU (8.9.1a/8.9.1) id MAA09976
for icon-group-addresses; Mon, 4 Oct 1999 12:38:02 -0700 (MST)
Message-Id: <199910041938.MAA09976@baskerville.CS.Arizona.EDU>
From: eka@corp.cirrus.com (Eka Laiman)
Subject: Re: A small puzzle
To: sbw@tapestry.tucson.az.us (Steve Wampler)
Date: Mon, 4 Oct 1999 10:49:38 -0700 (PDT)
Cc: icon-group@optima.CS.Arizona.EDU
Errors-To: icon-group-errors@optima.CS.Arizona.EDU
Status: RO
> I haven't posted anything for a while, but thought this might be fun:
>
> Write an Icon program to generate the pairings in a round-robin
> tournament. The program should accept the player names as
> command line arguments (see the example below).
>
> In a round-robin tournament, every player plays every other player
> exactly once. If there are an odd number of players, then a
> special "bye" player is added.
> ................. edited ..................
If I understand the problem correctly, here is how I approach the
problem:
Model the problem as "graph" in the following sense:
Each player forms a vertex of the graph. Each pair of player
is an edge in the graph.
>From the condition that every player plays every other player exactly
once, we see the following graph property: each vertex is connected
to every vertex in the graph, forming a "complete graph".
Let N be the number of the vertices in the graph, clearly there are
N(N-1)/2
edges.
>From this analysis we come up with the following algorithm:
Let player[1..n] be the array of the players.
1. Set up the second array partner[1..n] such that:
partner[i] := player[n - i + 1]
# initialize partner as the reverse of player.
2. Repeat the following steps (n - 1) times:
2a. For i := 1 to n/2 do
write(pair(player[i], partner[i])
2b. Rotate array partner one step.
>From the rule of counting, we see that step 2 generates all edges
in our complete graph.
I think the implementation of the above algorithm is straightforward.
-eka-